new Vue({
  el: '#app',
  data() {
    return {
      form: {
        pageNow:1,
        pageSize: 10,		//每页数据条数
      },
      tableData: [],		//表格数据
      total: 1,
      key:'',
      person:'',
    }
  },
  mounted() {
    this.getList(this.form)
  },
  methods: {
    onSerach() {				//查询方法
      this.form.page = 1
      this.getList(this.form)
    },
    getList(data) {     //换页方法
      const _this = this
      $.ajax({
        headers,
        url: BASE_URL+'/weixin/queryMsgTemplate',
        type: 'GET',
        data,
        success: function (res) {
          console.log('模板', res);
          res.data.forEach(item => {
            if (typeof item.template_to === 'string') {
              item.template_to = JSON.parse(item.template_to).join(" ");  // 使用空格作为连接符
          }
          });
          _this.tableData = res.data
          _this.total = res.countlength
        },
        error: function () {
          _this.$message.error("操作失败，请稍后再试");
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      });
    },
    sendMember(data){
      console.log('id',data);
      const _this = this
      $.ajax({
        url: BASE_URL+'/weixin/sendMsgTemplate',
        type: 'POST',
        data:{
          define_templates_info_id: data
        },
        success: function (res) {
          console.log('发送消息', res);
          if(res.status === 0){
            _this.$message.success("发送成功")
          }
        },
        error: function () {
          _this.$message.error("操作失败，请稍后再试");
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      });
    },
    addEnterprise() {
      window.location.href = './Add.html?token='+$.cookie("token")
    },
    // editMember(Wechat_Template_SerialNumber) {
    //   sessionStorage.setItem("Wechat_Template_SerialNumber", Wechat_Template_SerialNumber)
    //   window.location.href = './Edit.html'
    // },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //点击按钮
    deletMember(row) {
      const _this = this;
      this.$confirm('此操作将删除该信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        _this.Delete(row);
      }).catch(() => {
        this.$message({
          type: 'warning',
          message: '已取消删除'
        });
      });
    },
    //删除
    Delete(row) {
      const _this = this;
      $.ajax({
        url: DomainName + '/DeleteAction?token=' + $.cookie('token'),
        type: 'POST',
        data:{
          TableName:'wechat_template',
          Primary_Key:row.Wechat_Template_SerialNumber,
          Primary_Key_Name:'Wechat_Template_SerialNumber'
        },
        error: function (array) {
          console.log(array);
          _this.$message.error("删除失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        success: function (res) {
          if (res.Status == 'success') {
            _this.$message({
              type: 'success',
              message: '删除成功!'
            });
            _this.getList(_this.form)
          }
        }
      })
    },
    
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
  },
})